package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {

    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;

    //获取整个列表,没有查询条件
    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") StrategyQueryObject qo){
        qo.setPageSize(8);
        model.addAttribute("result",strategyCatalogService.query(qo));
        model.addAttribute("strategies",strategyService.list());
        return "strategyCatalog/list";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(StrategyCatalog entity){
        strategyCatalogService.saveOrUpdate(entity);
        return "redirect:/strategyCatalog/list.do";
    }

    @RequestMapping("/getByStrategyId")
    @ResponseBody
    public Object getByStrategyId(Long strategyId){
        return strategyCatalogService.selectByStrategyId(strategyId);
    }
}
